package com.qhg.saas_server.controller;

import com.github.pagehelper.PageInfo;
import com.qhg.saas_server.empty.Result;
import com.qhg.saas_server.pojo.Orders;
import com.qhg.saas_server.pojo.OrdersProduct;
import com.qhg.saas_server.pojo.dto.OrdersCondition;
import com.qhg.saas_server.pojo.dto.OrdersProductDto;
import com.qhg.saas_server.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@CrossOrigin
@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @PostMapping("/search")   //分页查询与条件查询
    public Result<PageInfo<Orders>> searchOrders(@RequestBody OrdersCondition ordersCondition){
//        System.out.println("数据是"+ordersCondition.currentPage+ordersCondition.displayCount);
        return Result.success(ordersService.searchOrders(ordersCondition));
    }
    @PostMapping("/insert")   //添加订单
    public ResponseEntity<OrdersProductDto> insert(@RequestBody OrdersProductDto ordersProductDto){
        return ResponseEntity.ok(this.ordersService.insert(ordersProductDto));
    }
    @DeleteMapping("/delete/{orderId}/{orderType}")    //删除订单
    public Result<Integer> delete(@PathVariable("orderId") String orderId,@PathVariable("orderType") String orderType){
        return Result.success(ordersService.delete(orderId,orderType));
    }
    @GetMapping("/select/{orderId}")     //根据订单号查找商品明细
    public Result<OrdersProductDto> select(@PathVariable("orderId") String orderId){
        return Result.success(ordersService.select(orderId));
    }
    @PutMapping("/update")       //更新订单信息
    public Result<Integer> update(@RequestBody OrdersProductDto ordersProductDto){
        return Result.success(ordersService.update(ordersProductDto));
    }
}
